package com.mb.note.service.impl;

import cn.hutool.json.JSONObject;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.lijian.common.domain.R;
import com.mb.note.domain.dto.NoteTitle;
import com.mb.note.domain.po.Note;
import com.mb.note.mapper.NoteMapper;
import com.mb.note.service.NoteService;
import io.swagger.models.auth.In;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.LinkedList;
import java.util.List;

/**
 * <p>
 * 商品表 服务实现类
 * </p>
 *
 * @author 虎哥
 */
@Service
public class NoteServiceImpl extends ServiceImpl<NoteMapper, Note> implements NoteService {
    @Resource
    private NoteMapper noteMapper;
    @Override
    public List<JSONObject> getNoteTitleList(String fid) {
        List<NoteTitle> noteTitleList = noteMapper.getNoteTitleList(fid);
        List<Integer> sids = noteMapper.getSids(fid);

        int i = 0;
        List<JSONObject> jsonObjectList = new ArrayList<>();//存sid=11的title集合
        for (Integer sid :sids) { //sid=11
            JSONObject jsonObject = new JSONObject();
            jsonObject.put("name", noteMapper.getName(sid));
            List<JSONObject> jsonObjectList2 = new LinkedList<>();//存sid=11的title集合
            for (; i < noteTitleList.size(); i++) {
                if (noteTitleList.get(i).getSid() == sid) {
                    JSONObject jsonObject2 = new JSONObject();
                    jsonObject2.put("title", noteTitleList.get(i).getTitle());
                    jsonObject2.put("id", noteTitleList.get(i).getId());
                    jsonObjectList2.add(jsonObject2);
                }else {
                    jsonObject.put("value",jsonObjectList2);
                    break;
                }
            }
            jsonObjectList.add(jsonObject);
        }
        return jsonObjectList;
    }
}
